package com.neuedu.autosale.cli.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.neuedu.autosale.cli.entity.Feedback;
import com.neuedu.autosale.cli.service.FeedbackService;
import com.neuedu.autosale.entity.Pager;
import com.neuedu.autosale.entity.Result;

@Controller
public class FeedbackController {
	@Autowired
	private FeedbackService feedbackService;
	
	@RequestMapping("feedback/index")
	private String feedbackIndex() {
		return "client/feedbacklist";
	}
	
	@RequestMapping("feedback/list")
	@ResponseBody
	public Pager<Feedback> feedbackList(@RequestParam(value = "page", defaultValue = "1") Integer page,
			@RequestParam(value = "rows", defaultValue = "10") Integer rows){
		Pager<Feedback> pager=new Pager<>(page,rows);
		List<Feedback> feedbackList=feedbackService.findListByPager(pager);
		int total =feedbackService.findTotalByPager(pager);
		pager.setRows(feedbackList);
		pager.setTotal(total);
		return pager;
	}
	
	@RequestMapping("feedback/add")
	@ResponseBody
	public Result doAdd(Feedback feedback) {
		Result result=feedbackService.add(feedback);
		return result;
	}
	
	@RequestMapping("feedback/edit")
	@ResponseBody
	public Result result(Feedback feedback) {
		Result result =feedbackService.edit(feedback);
		return result;
	}
	
	@RequestMapping("feedback/delete")
	@ResponseBody
	public Result doDelete(Integer feedbackId) {
		List<Feedback> list=new ArrayList<Feedback>();
		list.add(new Feedback(feedbackId));
		Result result=feedbackService.deleteByIds(list);
		return result;
	}
	

}
